package com.ykt.converter;

import com.ykt.common.utils.UB;
import com.ykt.model.Category;
import com.ykt.model.GoodsCategory;
import com.ykt.vo.GoodsCategoryVo;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: long.hua
 * @date: 2016-04-20 13:05
 * @since 1.0
 */
public class GoodsCategoryConverter {


    public static GoodsCategoryVo convert(GoodsCategory model){
        if(model == null){
            return null;
        }

        GoodsCategoryVo vo = new GoodsCategoryVo();
        BaseConverter.convert(vo, model);

        vo.setShopId(UB.i(model.get(GoodsCategory.shop_id)));
        vo.setPid(UB.i(model.get(Category.pid)));
        vo.setIcon(model.getStr(Category.icon));
        vo.setCategoryId(UB.i(model.get(GoodsCategory.id), -1));
        vo.setCategoryName(model.getStr(GoodsCategory.name));
        vo.setCategoryIcon(model.getStr(GoodsCategory.icon));

        return vo;
    }

    public static List<GoodsCategoryVo> convert(List<GoodsCategory> models){
        if(models == null || models.isEmpty()){
            return null;
        }

        List<GoodsCategoryVo>  vos = new ArrayList<>();

        for (GoodsCategory model : models) {
            vos.add(convert(model));
        }

        return vos;
    }
}
